<?php 
class CommonController extends Controller{
	private $model;
	public function __init(){
		$this->model=K("Category");
	}
	
	public function cate(){
		
		//左侧导航栏************
	
		//查找顶级分类
		$Father=$this->model->where("pid=0")->all();
		
		
		//查找子分类并压入父类
		foreach ($Father as $k => $v) {
			$Father[$k]['son']=$this->model->where("pid={$v['cid']}")->limit('0,3')->all();
			
		}
		foreach ($Father as $k => $v) {
			$Father[$k]['sons']=$this->model->where("pid={$v['cid']}")->all();
			
		}
		
		return $Father;
	}
	public function nav(){
	//查找hover下面的全部分类
		//导航栏**************
       
		//查找顶级分类
		$nav=$this->model->where("pid=0")->limit("0,7") ->all();
		return $nav;
		
	}
	
	/**
	 * 递归获得父级
	 */
	 protected function _getFatherCate($data,$cid){
		$temp = array();
		foreach ($data as $v) {
			if($v['cid'] == $cid){
				$temp[] = $v;
				$temp = array_merge($temp,$this->_getFatherCate($data, $v['pid']));
			}
		}
		return $temp;
	}
	 
	 
	 
	 
	
}



 ?>